package com.punch.course.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punch.common.utils.BigDecimalUtil;
import com.punch.common.vo.course.goods.SimpleGoodsVO;
import com.punch.course.mapper.GoodsMapper;
import com.punch.course.model.Goods;
import com.punch.course.service.GoodsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author wjj
 * @since 2020-12-11
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    /**
     * 课程下选择教具/教材
     *
     * @return List<SimpleGoodsVO>
     */
    @Override
    public List<SimpleGoodsVO> listSimpleGoods() {
        List<SimpleGoodsVO> retList = new ArrayList<>();
        list().forEach(goods -> {
            SimpleGoodsVO simpleGoodsVO = new SimpleGoodsVO();
            simpleGoodsVO.setGoodsId(goods.getId());
            simpleGoodsVO.setGoodsName(goods.getGoodsName());
            simpleGoodsVO.setGoodsPrice(BigDecimalUtil.getMoneyBigDecimal(goods.getGoodsPrice()));
            retList.add(simpleGoodsVO);
        });
        return retList;
    }
}
